﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using DnD.ViewModels;
using DnD.Model;

namespace DnD
{
    public partial class DeckPage : PhoneApplicationPage
    {
        public DeckPage()
        {
            InitializeComponent();
        }


        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            string deckIDString;
            if (NavigationContext.QueryString.TryGetValue("deckID", out deckIDString))
            {
                int deckID;
                if (int.TryParse(deckIDString, out deckID))
                {
                    DataContext = new DeckViewModel(deckID,this);
                }

            }
        }

        private void CardList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ((DeckViewModel)DataContext).SelectedCard = ((LongListSelector)sender).SelectedItem as Card;
            //NavigationService.Navigate(new Uri("/CardPage.xaml", UriKind.Relative));
        }
    }
}